package code;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
@WebFilter("/chat.jsp")
public class filter implements Filter {
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        Object user=((HttpServletRequest) servletRequest).getSession().getAttribute("name");
        if(user==null)
        {
            System.out.println("验证失败");
            servletRequest.getRequestDispatcher("/login.html").forward(servletRequest, servletResponse);
        }
        else
        {
            System.out.println("验证成功");
            filterChain.doFilter(servletRequest, servletResponse);
        }
    }
}
